<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <title>分类</title>
  <meta name="renderer" content="webkit">
  <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
  
    {include file="public/css"}
    {include file="public/js"}
</head>
<body>

<!-- 后台面包屑导航 -->
{:get_admin_breadcrumb()}
<!-- 搜索表单 -->
{:create_search_form("添加分类",$keywordsData,$customSingleField,$groupData,$dateData,$orderData)}

<div class="layui-form">
  <table class="layui-table" id="demo">
    <colgroup>
      <col width="50">
      <col width="70">
      <col width="120">
      <col width="350">

      <col width="130">
      <col width="180">
      <col width="310">
      <col>
    </colgroup>
    <thead>

      <tr>
        <th><input type="checkbox"  id="selectAll"  lay-skin="primary" lay-filter="selectAll"></th>
        <th>ID</th>
        <th>排序</th>
        <th>分类名称</th>
        <th>字母缩写</th>
        <th>状态</th>
        <th>操作</th>
      </tr> 
    </thead>
    <tbody>

{volist name='list' id='vo'}
      <tr data-id="{$vo.cid}">
        <td><input type="checkbox" name="cid[]" class="id " title=""  lay-skin="primary" value="{$vo.cid}"></td>
      
        <td>{$vo.cid}</td>
        <td>{$vo.sort}</td>

        <td><a href="{:url('@'.$type.'/lists/index',['alias'=>$vo.alias])}" target="_blank">{$vo.cname}</a></td>
        <td>{$vo.alias}</td>
       
        </td>
   
        <td><input type="checkbox" class="status_{$vo.cid}" name="close" {if $vo.status ==1}checked{/if} lay-skin="switch" lay-filter="switchStatus" lay-text="显示|隐藏"></td>
        <td>
        <div class="layui-btn-group">
          <button class="layui-btn layui-btn-sm layui-btn-normal" id="edit" onclick="blank('{:url($type."/categoryEdit",array("cid"=>$vo["cid"]))}','编辑分类','580px','90%')" title="编辑分类"> <i class="layui-icon">&#xe642;</i></button>
          <button class="layui-btn layui-btn-sm layui-btn-primary" onclick="del('{:url($type."/categoryDel",array("cid"=>$vo["cid"]))}')" title="删除分类"> <i class="layui-icon">&#xe640;</i></button>
         </div>
 </td>
      </tr>
{/volist}

    </tbody>
  </table>
<!-- 搜索为空显示 -->
{if empty($list)}
 <div class="layui-form-item">
    <div class="empty">
     <div class="img"></div>
     <p>暂无内容</p></div>
 </div>
</div>
{/if}


</div>

<div id="pages">{$page|raw}</div>

<div class="layui-btn-group demoTable">

  <button class="layui-btn layui-btn-primary" id="del" data-type="getCheckData"> <i class="layui-icon">&#xe640;</i> 批量删除</button>
</div>

<!-- 注意：如果你直接复制所有代码到本地，上述js路径需要改成你本地的 -->
<script>
layui.use(['element', 'layer','form','table', 'layedit', 'laydate'], function(){
   var  element = layui.element, layer = layui.layer,form = layui.form ,layedit = layui.layedit
  ,laydate = layui.laydate;
var table = layui.table;


// 多选框切换
form.render();
form.on('switch(switchStatus)', function(data){
   var  status = data.elem.checked;
  var id =$(this).parents("tr").attr("data-id");
  var status = data.elem.checked;
  if(status == true ){ status =1; }else{status = 0;}
    $.post('{:url($type."/categoryUpdate")}',{"type":"{$type}","cid":id,"status":status},function(json){
        if(json.code = 1){
          layer.msg(json.msg);
        }
     });
});

});

</script>
<script>
$(function(){
 //全选批量删除
        var id = []; //定义空数组
        var url ="{:url($type.'/categoryDel')}"; //请求的url
        var data = {"cid":id};   //传递的表单数据
        var delButton = "#del"; //删除节点class 或者ID
        var checkboxClass = ".id"; //多选框class
       

         $(delButton).click(function(){
              $(checkboxClass).each(function() {
              if(this.checked == true){
                   id.push($(this).val()); 
              }
              });              
         if(id.length == 0){
            parent.layer.alert('你没有选中任何分类',{title:'批量删除提示'});
         }else{
                     var index =parent.layer.confirm('批量删除后，数据不可恢复', {
                      btn: ['确定删除','取消'] //按钮
                      ,title:'是否批量删除'
                      ,shadeClose:true
                      ,icon: 3
                      ,anim: 5  //动画类型
                    }, function(){
                      parent. layer.close(index);
                    // 确定ajax 删除数据
                                $.post(url,data        
                                     ,function(json){
                                      if(json.code == 0){
                                          parent.layer.msg(json.msg);
                                               setTimeout(function(){ 
                                                     window.location.reload();  //页面刷新
                                                },1000);
                                           }else{
                                            parent.layer.msg(json.msg);
                                           }
                                         }
                                       );

                    }, function(){
                       // 取消
                   
                    });

         }

    });

$("#add").on("click",function(){
  blank('{:url($type."/categoryAdd")}','添加分类','580px','90%');
});


  // 失去焦点更新表单
$("input").on("blur",function(){
var id =$(this).parents("tr").attr("data-id");
var sort = $(".sort_"+id).val();
    $.post('{:url($Request.controller."/categoryUpdate")}',{"type":"{$type}","cid":id,"sort":sort},function(json){
        if(json.code == 0){
          qilecms.success(json.msg);
        } 
     }
  );
});
});
</script>
</body>

</html>